<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{common/header :: commonHead}"></head>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight"
     th:with="page=${pageObj.page},size=${pageObj.pageSize},total=${pageObj.total},totalPage=${pageObj.totalPage},keyword=${pageObj.keyword}">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="ibox-tools">
                        <a href="/admin/add" title="添加"><i class="glyphicon glyphicon-plus-sign"></i></a>
                        <a href="javascript: window.location.href='/admin/list';" title="刷新"><i
                                class="glyphicon glyphicon-repeat"></i></a>
                    </div>
                    <div id="editable_wrapper" class="dataTables_wrapper form-inline" role="grid">
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_length" id="editable_length"><label>每页
                                    <select name="editable_length" aria-controls="editable"
                                            class="form-control input-sm" id="page_size_selector">
                                        <option th:selected="${size eq 5}" value="5">5</option>
                                        <option th:selected="${size eq 10}" value="10">10</option>
                                        <option th:selected="${size eq 25}" value="25">25</option>
                                        <option th:selected="${size eq 50}" value="50">50</option>
                                        <option th:selected="${size eq 100}" value="100">100</option>
                                    </select> 条记录</label>
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-group" style="float: right">
                                    <input th:value="${pageObj.keyword}" type="text" placeholder="请输入账号或名称" class="input-sm form-control" id="search_bar">
                                    <span class="input-group-btn">
                                    <button type="button" class="btn btn-sm btn-primary" id="search-btn"> 搜索</button>
                                </span>
                                </div>
                            </div>
                        </div>
                        <table class="table table-striped table-bordered table-hover  dataTable" id="editable"
                               aria-describedby="editable_info">
                            <thead>
                            <tr role="row">
                                <th aria-label="账号" style="width: 10%;">账号</th>
                                <th aria-label="名称" style="width: 15%;">名称</th>
                                <th aria-label="级别" style="width: 15%;">级别</th>
                                <th aria-label="操作" style="width: 10%;">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr class="gradeA odd" th:if="${#lists.isEmpty(pageObj.list)}">
                                <td colspan="9" style="text-align: center">
                                    没有数据o&gt;^&lt;o
                                </td>
                            </tr>
                            <tr class="gradeA odd" th:each="item : ${pageObj.list}">
                                <td th:with="keyword=${pageObj.keyword},account=${item.account}" th:utext="${null == keyword ? account : #strings.replace(account,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                <td th:with="keyword=${pageObj.keyword},name=${item.name}" th:utext="${null == keyword ? name : #strings.replace(name,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                <td th:text="${item.storeName}"></td>
                                <td class="center">
                                    <a type="button" th:href="${'/admin/edit?id='+item.id}" class="btn btn-primary btn-xs" title="编辑">编辑</a>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_info" role="alert" aria-live="polite" aria-relevant="all"
                                     th:text="${'显示 '
                                      + (page * size + 1)
                                      + ' 到 '
                                      + ((page+1) lt totalPage ? (size + page * size) : (total % size == 0 ? total : (total % size + size * page)))
                                      + ' 项，共 '
                                      + total + ' 项 ' + totalPage + ' 页'}">
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_simple_numbers">
                                    <ul class="pagination" th:if="${totalPage>1}">
                                        <li th:class="${page==0}?'paginate_button previous disabled':'paginate_button previous'">
                                            <a th:href="${(page==0)?'#':'/admin/list?page='+page
                                             +'&pageSize='+size
                                             +'&keyword='+(null==keyword?'':keyword)}">上一页</a>
                                        </li>
                                        <li th:if="${totalPage<10}" th:each="i:${#numbers.sequence(1,totalPage)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/admin/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:if="${page<4&&totalPage>=9}" th:each="i:${#numbers.sequence(1,9)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/admin/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:if="${page>=4&&totalPage>=9&&page+5<totalPage}"
                                            th:each="i:${#numbers.sequence(page - 3,page + 5)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/admin/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:if="${page>=4&&totalPage>=9&&page+5>=totalPage}"
                                            th:each="i:${#numbers.sequence(totalPage - 8,totalPage)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/admin/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:class="${page+1==totalPage||totalPage<1}?'paginate_button next disabled':'paginate_button next'">
                                            <a th:href="${(page+1==totalPage||totalPage<1) ? '#' : '/admin/list?page='+(page+2)
                                             +'&pageSize='+size
                                             +'&keyword='+(null==keyword?'':keyword)}">下一页</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script th:inline="javascript">
    $("#page_size_selector").change(function () {
        let selected = $(this).val();
        window.location.href = initUrl(0, selected, '');
    })
    $("#search_bar").keydown(function (e) {
        if (e.keyCode == 13) {
            let size = [[${size}]];
            let keyword = $(this).val();
            window.location.href = initUrl(0, size, keyword);
        }
    })

    $("#search-btn").click(function () {
        let size = [[${size}]];
        let keyword = $("#search_bar").val();
        window.location.href = initUrl(0, size, keyword);
    })

    function initUrl(page, size, key) {
        if (null == page) {
            page = 0;
        }
        if (null == size) {
            size = 10;
        }
        return "/admin/list?page=" + page + "&pageSize=" + size + "&keyword=" + key
    }
</script>
</html>